<template>
  <div class="modern-carousel-container">
    <div class="carousel-inner">
      <el-carousel 
        :interval="5000" 
        arrow="always" 
        height="500px"
        indicator-position="outside"
        class="modern-carousel"
      >
        <el-carousel-item v-for="(item, index) in carouselItems" :key="index">
          <div class="carousel-slide" :style="{ backgroundImage: `url(${item.image})` }">
            <div class="carousel-overlay"></div>
            <div class="carousel-content">
              <div class="carousel-badge" v-if="item.badge">{{ item.badge }}</div>
              <h2 class="carousel-title">{{ item.title }}</h2>
              <p class="carousel-description">{{ item.description }}</p>
              <div class="carousel-price" v-if="item.price">
                <span class="price-label">特惠价</span>
                <span class="price-currency">¥</span>
                <span class="price-amount">{{ item.price }}</span>
                <span class="price-original" v-if="item.originalPrice">¥{{ item.originalPrice }}</span>
              </div>
              <div class="carousel-buttons">
                <el-button type="success" class="action-button" @click="goToProduct(item)">
                  立即购买
                  <i class="el-icon-shopping-cart-2"></i>
                </el-button>
                <el-button class="details-button" @click="viewDetails(item)">
                  了解详情
                  <i class="el-icon-right"></i>
                </el-button>
              </div>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
    
    <div class="carousel-thumbnails">
      <div 
        v-for="(item, index) in carouselItems" 
        :key="index"
        class="thumbnail-item"
        :class="{ active: currentIndex === index }"
        @click="setCurrentSlide(index)"
      >
        <div class="thumbnail-image" :style="{ backgroundImage: `url(${item.image})` }"></div>
        <div class="thumbnail-title">{{ item.title }}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'FrontCarousel',
  data() {
    return {
      currentIndex: 0,
      carouselItems: [
        {
          title: '有机蔬菜礼盒',
          description: '精选当季有机蔬菜，健康美味，新鲜直达',
          image: 'https://img.freepik.com/free-photo/vegetables-set-left-black-slate_1220-685.jpg',
          badge: '新品',
          price: '199.00',
          originalPrice: '299.00',
          id: 1
        },
        {
          title: '精选水果组合',
          description: '甄选全球优质水果，营养丰富，口感极佳',
          image: 'https://img.freepik.com/free-photo/delicious-healthy-fruits-arrangement_23-2148846310.jpg',
          badge: '热销',
          price: '159.00',
          originalPrice: '259.00',
          id: 2
        },
        {
          title: '五谷杂粮礼盒',
          description: '传统工艺，天然无添加，营养丰富',
          image: 'https://img.freepik.com/free-photo/cereals-beans-assortment-wooden-spoons-wooden-table_1150-42385.jpg',
          badge: '限时',
          price: '129.00',
          originalPrice: '199.00',
          id: 3
        }
      ]
    }
  },
  methods: {
    goToProduct(item) {
      this.$router.push(`/product/${item.id}`)
    },
    viewDetails(item) {
      this.$router.push({
        path: `/product/${item.id}`,
        query: { showDetails: true }
      })
    },
    setCurrentSlide(index) {
      this.currentIndex = index
      // 如果使用Element UI的轮播图，可能需要额外的逻辑来控制当前显示的幻灯片
    }
  }
}
</script>

<style scoped>
.modern-carousel-container {
  margin: 40px auto;
  max-width: 1200px;
  padding: 0 20px;
}

.carousel-inner {
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
}

.modern-carousel {
  border-radius: 16px;
}

.carousel-slide {
  height: 100%;
  width: 100%;
  background-size: cover;
  background-position: center;
  position: relative;
}

.carousel-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.4) 50%, rgba(0,0,0,0.1) 100%);
  z-index: 1;
}

.carousel-content {
  position: absolute;
  left: 8%;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  max-width: 500px;
  color: white;
  text-align: left;
}

.carousel-badge {
  display: inline-block;
  background: linear-gradient(135deg, #4caf50, #81c784);
  color: white;
  padding: 6px 14px;
  border-radius: 30px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  box-shadow: 0 4px 10px rgba(76, 175, 80, 0.3);
}

.carousel-title {
  font-size: 42px;
  font-weight: 700;
  margin: 0 0 16px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  line-height: 1.2;
}

.carousel-description {
  font-size: 18px;
  line-height: 1.6;
  margin-bottom: 24px;
  opacity: 0.9;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.carousel-price {
  margin-bottom: 24px;
  display: flex;
  align-items: baseline;
}

.price-label {
  background: #ff6b6b;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 14px;
  margin-right: 10px;
}

.price-currency {
  font-size: 20px;
  font-weight: 600;
  margin-right: 2px;
}

.price-amount {
  font-size: 36px;
  font-weight: 700;
}

.price-original {
  font-size: 16px;
  text-decoration: line-through;
  opacity: 0.7;
  margin-left: 10px;
}

.carousel-buttons {
  display: flex;
  gap: 16px;
}

.action-button {
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 8px;
  background: linear-gradient(135deg, #4caf50, #81c784);
  border: none;
  box-shadow: 0 4px 10px rgba(76, 175, 80, 0.3);
  transition: all 0.3s ease;
}

.action-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(76, 175, 80, 0.4);
  background: linear-gradient(135deg, #43a047, #66bb6a);
}

.details-button {
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  backdrop-filter: blur(5px);
  transition: all 0.3s ease;
}

.details-button:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.5);
}

.carousel-thumbnails {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-top: 20px;
}

.thumbnail-item {
  width: 120px;
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.3s ease;
  opacity: 0.7;
  position: relative;
}

.thumbnail-item:hover {
  opacity: 0.9;
}

.thumbnail-item.active {
  opacity: 1;
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.thumbnail-item.active::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 30px;
  height: 3px;
  background: #4caf50;
  border-radius: 3px;
}

.thumbnail-image {
  height: 70px;
  background-size: cover;
  background-position: center;
}

.thumbnail-title {
  font-size: 12px;
  padding: 8px;
  text-align: center;
  background: white;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 响应式布局 */
@media (max-width: 992px) {
  .carousel-content {
    max-width: 400px;
  }
  
  .carousel-title {
    font-size: 36px;
  }
  
  .carousel-description {
    font-size: 16px;
  }
}

@media (max-width: 768px) {
  .modern-carousel-container {
    padding: 0 15px;
  }
  
  .carousel-content {
    max-width: 320px;
    left: 5%;
  }
  
  .carousel-title {
    font-size: 28px;
  }
  
  .carousel-description {
    font-size: 14px;
    margin-bottom: 16px;
  }
  
  .carousel-price {
    margin-bottom: 16px;
  }
  
  .price-amount {
    font-size: 28px;
  }
  
  .carousel-buttons {
    flex-direction: column;
    gap: 10px;
  }
  
  .action-button, .details-button {
    padding: 10px 20px;
    font-size: 14px;
  }
  
  .carousel-thumbnails {
    display: none;
  }
}

@media (max-width: 480px) {
  .carousel-content {
    max-width: 280px;
  }
  
  .carousel-title {
    font-size: 24px;
    margin-bottom: 10px;
  }
  
  .carousel-description {
    font-size: 13px;
    margin-bottom: 12px;
  }
  
  .carousel-badge {
    font-size: 12px;
    padding: 4px 10px;
    margin-bottom: 10px;
  }
}
</style> 